Advertisement
DeaD_EyE

Steam: show state of fossilize_replay (tested on Linux) with logfile

May 4th, 2024 (edited)
654
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.55 KB | None | 0 0
  1. import re
  2. import time
  3. from datetime import datetime as DateTime
  4. from functools import cache
  5. from pathlib import Path
  6.  
  7. import requests
  8.  
  9. reg = re.compile(r"\[(?P<year>\d{4})-(?P<month>\d{2})-(?P<day>\d{2}) (?P<hour>\d{2}):(?P<minute>\d{2}):(?P<second>\d{2})\] Still replaying (?P<appid>\d+) \(\d{2}%, (?P<done>\d+)\/(?P<total>\d+)\)")
  10.  
  11.  
  12. @cache
  13. def appids():
  14.     return {
  15.         app["appid"]: app["name"]
  16.         for app in requests.get(
  17.             "https://api.steampowered.com/ISteamApps/GetAppList/v2/"
  18.         ).json()["applist"]["apps"]
  19.     }
  20.  
  21.  
  22. def names_shadercache():
  23.     return [appids()[appid] for appid in appids_shadercache()]
  24.  
  25.  
  26. def mktime(result: dict) -> DateTime:
  27.     return DateTime(
  28.         *(
  29.             int(result[name])
  30.             for name in ("year", "month", "day", "hour", "minute", "second")
  31.         )
  32.     )
  33.  
  34.  
  35. def read_log():
  36.     with Path.home().joinpath(".local/share/Steam/logs/shader_log.txt").open() as fd:
  37.         while True:
  38.             line = fd.readline().rstrip()
  39.             if not line:
  40.                 continue
  41.             if match := reg.search(line):
  42.                 result = match.groupdict()
  43.                 dt = mktime(result)
  44.                 game = appids().get(int(result["appid"]), "Unknown")
  45.                 progress = int(result["done"]) / int(result["total"])
  46.                 print("\033c", end="")
  47.                 print(f"[{dt}] [{progress:06.2%}] {game}")
  48.  
  49.                
  50. if __name__ == "__main__":
  51.     read_log()
  52.  
  53.  
  54. # [2024-05-04 13:57:35] Still replaying 730 (80%, 1572280/1941272).
  55.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement